package com.demo.jdbc.e_jdbcdaosupport;

import com.demo.jdbc.a_domain.User;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import java.util.List;

public class UserDao extends JdbcDaoSupport{
    
    public void update(User user){
        String sql="UPDATE t_user set username=?,password=? WHERE id=?";
        Object[] args={user.getUsername(),user.getPassword(),user.getId()};
        this.getJdbcTemplate().update(sql,args);
    }
    
    /**
     * 查询所有
     * @return
     */
    public List<User> findAll() {
        return this.getJdbcTemplate().query("SELECT * FROM t_user", ParameterizedBeanPropertyRowMapper.newInstance(User.class));
    }
    
}
